#include "ring_buffer.h"

void ring_init(RingBuffer *rb, uint8_t *buf, int size) {
    rb->buffer = buf;
    rb->size = size;
    rb->head = rb->tail = rb->count = 0;
}

bool ring_push(RingBuffer *rb, uint8_t data) {
    if (rb->count >= rb->size) return false;
    rb->buffer[rb->head] = data;
    rb->head = (rb->head + 1) % rb->size;
    rb->count++;
    return true;
}

bool ring_pop(RingBuffer *rb, uint8_t *data) {
    if (rb->count <= 0) return false;
    *data = rb->buffer[rb->tail];
    rb->tail = (rb->tail + 1) % rb->size;
    rb->count--;
    return true;
}

int ring_available(RingBuffer *rb) {
    return rb->count;
}